package com.ptmall.app.ui.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.ui.adapter.TradePagerAdapter;
import com.ptmall.app.ui.fragment.LogFragment;
import com.ptmall.app.ui.fragment.PtMsgFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MessageActivity extends BaseMvpActivity {

    TabLayout mTradeTabs;
    ViewPager mTradeViewpager;

    private TradePagerAdapter mPagerAdapter;
    private List<Fragment> mFragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_message);
    }

    @Override
    public void initViews() {
        mTradeViewpager = (ViewPager) findViewById(R.id.trade_viewpager);
        mTradeTabs = (TabLayout) findViewById(R.id.trade_tabs);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    public void initEvents() {
        mFragmentList.add(new PtMsgFragment());
        mFragmentList.add(new LogFragment());
        mPagerAdapter = new TradePagerAdapter(getSupportFragmentManager(), getContext(),
                Arrays.asList(getResources().getStringArray(R.array.msg_tab)),
                mFragmentList);
        mTradeViewpager.setAdapter(mPagerAdapter);
        mTradeTabs.setupWithViewPager(mTradeViewpager);
        mTradeTabs.setTabMode(TabLayout.MODE_FIXED);
        mTradeViewpager.setOffscreenPageLimit(mFragmentList.size());//
    }
}
